#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include "server.h"

int service_dispatch (int sock_fd)
{
	int req;
	recv(sock_fd, &req, sizeof(int), 0);
	switch (req)
	{
		case REG:
			reg(sock_fd);
			break;
		case LOG_IN:
			log_in(sock_fd);
			break;
		case LOG_IN2:
			log_in2(sock_fd);
			break;
		case LOG_OUT:
			log_out(sock_fd);
			break;
		case USER_LS:
			user_ls(sock_fd);
			break;
		case CHAT_TO:
			chat_to(sock_fd);
			break;
		case CHAT_TO_ALL:
			chat_to_all(sock_fd);
 			break;
		default:
			perror("no such service");
	}
	return 0;
}

user *get_user (char *name)
{
        int i;
        for (i = 0; i < USER_NUM_MAX; i++)
                if ( strcmp(name, users[i].name) == 0)
                        return &users[i];
        return NULL;
}
